class Object
  def my_instance_methods
    instance_methods - self.ancestors[1].instance_methods
  end
end

class VocabularyPopulator
  def self.populate(root_term, api_instance)
    root_term = Vocabulary.find_or_create_by_term(root_term)
    
    api_instance.class.my_instance_methods.each do |method|
      unless Vocabulary.find_by_term method
        Association.create :parent => root_term, :child => vocab(method)
      
        result = api_instance.send(method.to_sym, *[])
        populate(method, result) unless result.nil?
      end
    end
  end
  
  private
  def self.vocab(term)
    Vocabulary.create :term => term
  end
end